package com.springboot.mongodb.controller;

import com.springboot.mongodb.impl.HtmServiceImpl;
import com.springboot.mongodb.impl.LabelServiceImpl;
import com.springboot.mongodb.impl.UserServiceImpl;
import com.springboot.mongodb.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Optional;

/**
 * @ClassName springboot_mongodb - ViewController
 * @Description [此类用于: ]
 * @Author liming-jybdd@foxmail.com
 * @Date 2021/9/2616:46
 * @Version 1.0
 **/
@Controller
@RequestMapping("/view")
public class ViewController {

    @Autowired
    private LabelServiceImpl labelService;

    @Autowired
    private UserServiceImpl userService;

    @Autowired
    private HtmServiceImpl htmService;

    @RequestMapping("/userView")
    public String taskList(Model model) {
        model.addAttribute("viewList", labelService.findAllUser());
        model.addAttribute("htmList", htmService.findAllHtmMode());
        return "userView";
    }

    @RequestMapping("/model1")
    @ResponseBody
    public Page<User> getModel() {
        FindUserDTO findUserDTO = new FindUserDTO();
        findUserDTO.setPage(1);
        return userService.findAll(findUserDTO);
    }

    @RequestMapping("/htmById")
    @ResponseBody
    public Optional<HtmDepository> htmById(@RequestBody HtmDepository htmDepository) {
        return htmService.findByIdHtmMode(htmDepository);
    }

    @RequestMapping("/userHtmById")
    @ResponseBody
    public HtmVO userHtmById(@RequestBody Label label) {
        return htmService.userHtmById(label);
    }

}